Introduction

Welcome to the thrilling world of data visualization, where we transform mundane numbers into dazzling charts and graphs! Today, we’re diving into the depths of our incredibly exciting dataset, the Online Retail dataset from Kaggle. You know, that dataset that’s packed with such riveting details as invoice numbers, stock codes, and quantities. You can get the dataset from Kaggle.

Here’s the deal: We’ll be taking this data and turning it into visual masterpieces that’ll make you question why you ever thought raw data was anything but a visual feast. From heatmaps that could make your eyes bleed from their intensity, to scatter plots that boldly display the riveting relationship between transaction sizes and revenue — it’s all here.

Dataset Overview

So, what’s in store? Our dataset features columns that describe every tiny detail of your purchasing history. We’ve got invoices, stock codes, descriptions — basically, everything you could ever dream of to make a data analyst’s heart race.

Prepare yourself for a rollercoaster ride through the world of data visualization. Hold onto your seats — or at least your coffee — as we embark on this data-driven adventure!

a. Visualizing Transaction Patterns

Heatmaps and Time Series Plots

Heatmaps

Heatmaps visualize data density or intensity over a grid using color gradients. They’re ideal for showing trends in transaction volume or revenue over time.

# Load required libraries
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(reshape2)
library(lubridate) 
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
# Load your data
data <- read.csv("D:/PROJECTS/SQLProject/Market-Basket-Analysis/data/OnlineRetail.csv")

data$InvoiceDate <- as.POSIXct(data$InvoiceDate, format="%m/%d/%Y %H:%M", tz = "UTC")

# Extract Date, Hour, and Day of Week
data$Date <- as.Date(data$InvoiceDate)
data$Hour <- hour(data$InvoiceDate)
data$DayOfWeek <- weekdays(data$Date)

Heatmap of Average Transaction Size by Day of Week and Hour

# Calculate average transaction size
data_summary <- data %>%
  filter(Quantity > 0) %>%
  group_by(DayOfWeek, Hour) %>%
  summarize(AverageTransactionSize = mean(Quantity), .groups = 'drop')

# Reshape data for heatmap
data_heatmap <- dcast(data_summary, Hour ~ DayOfWeek, value.var = "AverageTransactionSize", fill = 0)

# Convert the data for plotly
data_heatmap_long <- melt(data_heatmap, id.vars = "Hour")

# Plot interactive heatmap using plotly
plot_ly(data_heatmap_long, x = ~variable, y = ~Hour, z = ~value, type = "heatmap",
        colors = c("lightblue", "darkblue"),
        colorbar = list(title = "Average Transaction Size")) %>%
  layout(title = "Heatmap of Average Transaction Size by Day of Week and Hour",
         xaxis = list(title = "Day of Week"),
         yaxis = list(title = "Hour of Day"),
         coloraxis = list(colorbar = list(title = "Average Transaction Size"))) %>%
  config(displayModeBar = TRUE)

Heatmap of Revenue by Day of Week and Hour

# Aggregation to calculate revenue by day of week and hour
data_summary <- data %>%
  filter(Quantity > 0) %>%
  group_by(DayOfWeek, Hour) %>%
  summarize(Revenue = sum(UnitPrice * Quantity), .groups = 'drop')

# Reshape data for heatmap
data_heatmap <- dcast(data_summary, Hour ~ DayOfWeek, value.var = "Revenue", fill = 0)

# Convert the data for plotly
data_heatmap_long <- melt(data_heatmap, id.vars = "Hour")

# Plot interactive heatmap using plotly
plot_ly(data_heatmap_long, x = ~variable, y = ~Hour, z = ~value, type = "heatmap",
        colors = c("white", "steelblue"),
        colorbar = list(title = "Revenue")) %>%
  layout(title = "Heatmap of Revenue by Day of Week and Hour",
         xaxis = list(title = "Day of Week"),
         yaxis = list(title = "Hour of Day"),
         coloraxis = list(colorbar = list(title = "Revenue"))) %>%
  config(displayModeBar = TRUE)

Time Series Plots

Time series plots help track changes over time, revealing trends in transaction volume and revenue.

# Time series plot of total revenue over time
data_time_series <- data %>%
  group_by(Date = as.Date(InvoiceDate)) %>%
  summarize(Revenue = sum(UnitPrice * Quantity), .groups = 'drop')

ggplot(data_time_series, aes(x = Date, y = Revenue)) +
  geom_line() +
  theme_minimal() +
  labs(title = "Revenue Over Time",
       x = "Date",
       y = "Revenue")

1. Aggregating the Data

Since your data has multiple items per invoice, you can aggregate it to find insights like total revenue per invoice, total quantity sold, etc. Here are a few ways you might aggregate the data:

  • Total Revenue per Invoice: Multiply Quantity by UnitPrice and sum it for each InvoiceNo.
  • Total Quantity per Invoice: Sum the Quantity for each InvoiceNo.
  • Average Revenue per Customer: Calculate the average revenue for each CustomerID.
head(data)
##   InvoiceNo StockCode                         Description Quantity
## 1    536365    85123A  WHITE HANGING HEART T-LIGHT HOLDER        6
## 2    536365     71053                 WHITE METAL LANTERN        6
## 3    536365    84406B      CREAM CUPID HEARTS COAT HANGER        8
## 4    536365    84029G KNITTED UNION FLAG HOT WATER BOTTLE        6
## 5    536365    84029E      RED WOOLLY HOTTIE WHITE HEART.        6
## 6    536365     22752        SET 7 BABUSHKA NESTING BOXES        2
##           InvoiceDate UnitPrice CustomerID        Country       Date Hour
## 1 2010-12-01 08:26:00      2.55      17850 United Kingdom 2010-12-01    8
## 2 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 3 2010-12-01 08:26:00      2.75      17850 United Kingdom 2010-12-01    8
## 4 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 5 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 6 2010-12-01 08:26:00      7.65      17850 United Kingdom 2010-12-01    8
##   DayOfWeek
## 1 Wednesday
## 2 Wednesday
## 3 Wednesday
## 4 Wednesday
## 5 Wednesday
## 6 Wednesday
# 2. Handle missing values
# Remove rows with any missing values (You can choose to impute instead)
data <- data %>%
  na.omit()

# 3. Remove negative quantities
data <- data %>%
  filter(Quantity > 0 )

# Check the first few rows to ensure the parsing is correct
head(data)
##   InvoiceNo StockCode                         Description Quantity
## 1    536365    85123A  WHITE HANGING HEART T-LIGHT HOLDER        6
## 2    536365     71053                 WHITE METAL LANTERN        6
## 3    536365    84406B      CREAM CUPID HEARTS COAT HANGER        8
## 4    536365    84029G KNITTED UNION FLAG HOT WATER BOTTLE        6
## 5    536365    84029E      RED WOOLLY HOTTIE WHITE HEART.        6
## 6    536365     22752        SET 7 BABUSHKA NESTING BOXES        2
##           InvoiceDate UnitPrice CustomerID        Country       Date Hour
## 1 2010-12-01 08:26:00      2.55      17850 United Kingdom 2010-12-01    8
## 2 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 3 2010-12-01 08:26:00      2.75      17850 United Kingdom 2010-12-01    8
## 4 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 5 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 6 2010-12-01 08:26:00      7.65      17850 United Kingdom 2010-12-01    8
##   DayOfWeek
## 1 Wednesday
## 2 Wednesday
## 3 Wednesday
## 4 Wednesday
## 5 Wednesday
## 6 Wednesday
# Inspect the cleaned data
summary(data)
##   InvoiceNo          StockCode         Description           Quantity       
##  Length:397924      Length:397924      Length:397924      Min.   :    1.00  
##  Class :character   Class :character   Class :character   1st Qu.:    2.00  
##  Mode  :character   Mode  :character   Mode  :character   Median :    6.00  
##                                                           Mean   :   13.02  
##                                                           3rd Qu.:   12.00  
##                                                           Max.   :80995.00  
##   InvoiceDate                       UnitPrice          CustomerID   
##  Min.   :2010-12-01 08:26:00.00   Min.   :   0.000   Min.   :12346  
##  1st Qu.:2011-04-07 11:12:00.00   1st Qu.:   1.250   1st Qu.:13969  
##  Median :2011-07-31 14:39:00.00   Median :   1.950   Median :15159  
##  Mean   :2011-07-10 23:43:36.91   Mean   :   3.116   Mean   :15294  
##  3rd Qu.:2011-10-20 14:33:00.00   3rd Qu.:   3.750   3rd Qu.:16795  
##  Max.   :2011-12-09 12:50:00.00   Max.   :8142.750   Max.   :18287  
##    Country               Date                 Hour        DayOfWeek        
##  Length:397924      Min.   :2010-12-01   Min.   : 6.00   Length:397924     
##  Class :character   1st Qu.:2011-04-07   1st Qu.:11.00   Class :character  
##  Mode  :character   Median :2011-07-31   Median :13.00   Mode  :character  
##                     Mean   :2011-07-10   Mean   :12.73                     
##                     3rd Qu.:2011-10-20   3rd Qu.:14.00                     
##                     Max.   :2011-12-09   Max.   :20.00

2. Visualizing the Aggregated Data

a) Total Revenue per Invoice

set.seed(123) 
sample_data <- data %>% sample_n(240000)
# Calculate total revenue per invoice
data_aggregated <- sample_data %>%
  group_by(InvoiceNo) %>%
  summarize(TotalRevenue = sum(Quantity * UnitPrice))%>%
  filter(TotalRevenue > 0)

print(min(data_aggregated$TotalRevenue))
## [1] 0.38
# Plot histogram of total revenue per invoice
ggplot(data_aggregated, aes(x = TotalRevenue)) +
  geom_histogram(bins = 3000, fill = "blue", color = "black") +
  coord_cartesian(xlim = c(-10, 2000), ylim = c(-10, 5000)) +
  theme_minimal() +
  labs(title = "Histogram of Total Revenue per Invoice",
       x = "Total Revenue",
       y = "Frequency")

b) Total Quantity per Invoice

# Calculate total quantity per invoice
data_aggregated <- sample_data %>%
  group_by(InvoiceNo) %>%
  summarize(TotalQuantity = sum(Quantity))

# Plot histogram of total quantity per invoice
ggplot(data_aggregated, aes(x = TotalQuantity)) +
  geom_histogram(bins = 1000, fill = "green", color = "black") +
  theme_minimal() +
  labs(title = "Histogram of Total Quantity per Invoice",
       x = "Total Quantity",
       y = "Frequency") +
  coord_cartesian(xlim = c(-10, 2000))

c) Average Revenue per Customer

# Calculate average revenue per customer
data_aggregated <- sample_data %>%
  group_by(CustomerID) %>%
  summarize(AverageRevenue = mean(Quantity * UnitPrice))

# Plot histogram of average revenue per customer
ggplot(data_aggregated, aes(x = AverageRevenue)) +
  geom_histogram(bins = 5000, fill = "orange", color = "black") +
  theme_minimal() +
  labs(title = "Histogram of Average Revenue per Customer",
       x = "Average Revenue",
       y = "Frequency")+
  coord_cartesian(xlim = c(-10, 200))

Yes, the tasks related to association rule mining can be performed in R. Here’s how you can approach each step of the process in R:

3. Association Rule Mining Preparation

a. Transaction Data Preparation

  1. Transform Transaction Data

    Transaction-Item Matrix

library(dplyr)
library(tidyr)
## 
## Attaching package: 'tidyr'
## The following object is masked from 'package:reshape2':
## 
##     smiths
library(arules)
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## 
## Attaching package: 'arules'
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
head(data)
##   InvoiceNo StockCode                         Description Quantity
## 1    536365    85123A  WHITE HANGING HEART T-LIGHT HOLDER        6
## 2    536365     71053                 WHITE METAL LANTERN        6
## 3    536365    84406B      CREAM CUPID HEARTS COAT HANGER        8
## 4    536365    84029G KNITTED UNION FLAG HOT WATER BOTTLE        6
## 5    536365    84029E      RED WOOLLY HOTTIE WHITE HEART.        6
## 6    536365     22752        SET 7 BABUSHKA NESTING BOXES        2
##           InvoiceDate UnitPrice CustomerID        Country       Date Hour
## 1 2010-12-01 08:26:00      2.55      17850 United Kingdom 2010-12-01    8
## 2 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 3 2010-12-01 08:26:00      2.75      17850 United Kingdom 2010-12-01    8
## 4 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 5 2010-12-01 08:26:00      3.39      17850 United Kingdom 2010-12-01    8
## 6 2010-12-01 08:26:00      7.65      17850 United Kingdom 2010-12-01    8
##   DayOfWeek
## 1 Wednesday
## 2 Wednesday
## 3 Wednesday
## 4 Wednesday
## 5 Wednesday
## 6 Wednesday
 # Filter out transactions with non-positive quantities
transaction_data <- data %>%
  filter(Quantity > 0)

# Aggregate items by InvoiceNo
aggregated_data <- transaction_data %>%
  group_by(InvoiceNo) %>%
  summarize(items = paste(StockCode, collapse = ",")) %>%
  ungroup()

# Split items into a list
split_items <- strsplit(aggregated_data$items, ",")

# Create a transactions object
basket_data <- as(split_items, "transactions")
## Warning in asMethod(object): removing duplicated items in transactions
# Check the summary of the transactions data
summary(basket_data)
## transactions as itemMatrix in sparse format with
##  18536 rows (elements/itemsets/transactions) and
##  3665 columns (items) and a density of 0.005709549 
## 
## most frequent items:
##  85123A   22423  85099B   47566   84879 (Other) 
##    1978    1704    1600    1380    1375  379838 
## 
## element (itemset/transaction) length distribution:
## sizes
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
## 1406  730  634  625  662  600  587  589  589  532  540  487  497  511  543  546 
##   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32 
##  460  432  477  432  392  337  340  305  243  250  240  237  268  218  193  173 
##   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48 
##  159  170  129  120  127  115  129  118  121   95   91   97   90   83   72   78 
##   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64 
##   83   78   52   59   67   68   63   44   56   44   32   52   39   25   39   33 
##   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80 
##   34   38   30   35   23   31   29   19   24   25   25   20   16   21   11   13 
##   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96 
##   17   21   15   18   16   12   11   13   12    8    9   15   13    6    5    8 
##   97   98   99  100  101  102  103  104  105  106  107  108  109  110  111  112 
##    9   12    3    9   11    3    6    7    2    3    5    4    3    3    5    3 
##  113  114  115  116  117  118  119  120  121  122  123  124  125  126  127  128 
##    3    5    5   10    3    4    4    6    5    7    3    4    3    2    4    2 
##  129  130  131  132  134  135  136  137  138  139  140  141  142  143  145  146 
##    1    2    2    3    1    3    2    1    3    1    1    4    1    1    3    2 
##  148  149  150  151  154  155  156  157  163  165  169  171  175  176  178  179 
##    1    3    1    1    1    1    1    1    1    2    1    2    1    2    1    1 
##  180  181  184  187  192  193  195  202  204  208  210  219  230  249  259  262 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
##  271  280  333  347  352  363  375  386  419  434  439  525  529  541 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.00    6.00   15.00   20.93   27.00  541.00 
## 
## includes extended item information - examples:
##   labels
## 1  10002
## 2  10080
## 3  10120
# Generate association rules with specified support and confidence
rules <- apriori(basket_data, parameter = list(support = 0.01, confidence = 0.5))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5    0.01      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 185 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[3665 item(s), 18536 transaction(s)] done [0.29s].
## sorting and recoding items ... [625 item(s)] done [0.01s].
## creating transaction tree ... done [0.02s].
## checking subsets of size 1 2 3 4 done [0.04s].
## writing ... [313 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
# Inspect the rules
inspect(rules)
##       lhs                      rhs      support    confidence coverage  
## [1]   {23172}               => {23171}  0.01089771 0.9017857  0.01208459
## [2]   {23171}               => {23172}  0.01089771 0.7481481  0.01456625
## [3]   {23172}               => {23170}  0.01062797 0.8794643  0.01208459
## [4]   {23170}               => {23172}  0.01062797 0.6006098  0.01769530
## [5]   {23175}               => {23174}  0.01111351 0.7573529  0.01467415
## [6]   {23174}               => {23175}  0.01111351 0.7686567  0.01445835
## [7]   {23175}               => {23173}  0.01035822 0.7058824  0.01467415
## [8]   {23173}               => {23175}  0.01035822 0.5423729  0.01909797
## [9]   {23174}               => {23173}  0.01057402 0.7313433  0.01445835
## [10]  {23173}               => {23174}  0.01057402 0.5536723  0.01909797
## [11]  {22569}               => {22570}  0.01084376 0.6836735  0.01586103
## [12]  {22570}               => {22569}  0.01084376 0.6203704  0.01747950
## [13]  {22627}               => {22624}  0.01003453 0.6118421  0.01640052
## [14]  {21086}               => {21094}  0.01273198 0.8280702  0.01537549
## [15]  {21094}               => {21086}  0.01273198 0.7261538  0.01753345
## [16]  {21086}               => {21080}  0.01035822 0.6736842  0.01537549
## [17]  {84997C}              => {84997D} 0.01230039 0.7402597  0.01661631
## [18]  {84997D}              => {84997C} 0.01230039 0.5377358  0.02287441
## [19]  {23254}               => {23256}  0.01154510 0.7753623  0.01488994
## [20]  {23256}               => {23254}  0.01154510 0.6604938  0.01747950
## [21]  {22192}               => {22193}  0.01014243 0.5562130  0.01823479
## [22]  {23294}               => {23295}  0.01041217 0.6632302  0.01569918
## [23]  {23295}               => {23294}  0.01041217 0.5376045  0.01936772
## [24]  {23294}               => {23293}  0.01089771 0.6941581  0.01569918
## [25]  {22570}               => {22568}  0.01078981 0.6172840  0.01747950
## [26]  {23171}               => {23170}  0.01235434 0.8481481  0.01456625
## [27]  {23170}               => {23171}  0.01235434 0.6981707  0.01769530
## [28]  {23296}               => {23295}  0.01025032 0.5956113  0.01720975
## [29]  {23295}               => {23296}  0.01025032 0.5292479  0.01936772
## [30]  {23296}               => {23293}  0.01159905 0.6739812  0.01720975
## [31]  {47590B}              => {47590A} 0.01370306 0.7075209  0.01936772
## [32]  {47590A}              => {47590B} 0.01370306 0.7154930  0.01915192
## [33]  {23173}               => {22699}  0.01025032 0.5367232  0.01909797
## [34]  {23173}               => {22423}  0.01046612 0.5480226  0.01909797
## [35]  {22725}               => {22726}  0.01132931 0.6521739  0.01737160
## [36]  {22725}               => {22727}  0.01219249 0.7018634  0.01737160
## [37]  {84997B}              => {84997D} 0.01035822 0.5889571  0.01758740
## [38]  {22191}               => {22193}  0.01078981 0.5115090  0.02109409
## [39]  {23170}               => {22699}  0.01025032 0.5792683  0.01769530
## [40]  {21136}               => {84879}  0.01375701 0.7244318  0.01899007
## [41]  {22746}               => {22745}  0.01105956 0.8134921  0.01359517
## [42]  {22745}               => {22746}  0.01105956 0.6487342  0.01704791
## [43]  {22746}               => {22748}  0.01159905 0.8531746  0.01359517
## [44]  {22748}               => {22746}  0.01159905 0.6213873  0.01866638
## [45]  {21668}               => {21669}  0.01138325 0.6336336  0.01796504
## [46]  {21669}               => {21668}  0.01138325 0.6011396  0.01893612
## [47]  {22729}               => {22726}  0.01186880 0.6128134  0.01936772
## [48]  {22729}               => {22727}  0.01327147 0.6852368  0.01936772
## [49]  {22632}               => {22865}  0.01014243 0.5236769  0.01936772
## [50]  {23295}               => {23293}  0.01327147 0.6852368  0.01936772
## [51]  {23293}               => {23295}  0.01327147 0.5290323  0.02508632
## [52]  {22579}               => {22578}  0.01219249 0.8188406  0.01488994
## [53]  {22578}               => {22579}  0.01219249 0.5219400  0.02335995
## [54]  {22579}               => {22577}  0.01078981 0.7246377  0.01488994
## [55]  {22661}               => {20724}  0.01019637 0.5510204  0.01850453
## [56]  {21094}               => {21080}  0.01235434 0.7046154  0.01753345
## [57]  {21933}               => {21932}  0.01073587 0.7031802  0.01526759
## [58]  {21932}               => {21933}  0.01073587 0.6238245  0.01720975
## [59]  {82581}               => {82580}  0.01213854 0.7450331  0.01629262
## [60]  {82580}               => {82581}  0.01213854 0.5874674  0.02066249
## [61]  {23243}               => {22720}  0.01154510 0.5558442  0.02077039
## [62]  {22745}               => {22748}  0.01370306 0.8037975  0.01704791
## [63]  {22748}               => {22745}  0.01370306 0.7341040  0.01866638
## [64]  {22625}               => {22624}  0.01429650 0.5902004  0.02422313
## [65]  {23343}               => {23344}  0.01321752 0.6363636  0.02077039
## [66]  {23439}               => {22865}  0.01095166 0.5471698  0.02001511
## [67]  {22749}               => {22750}  0.01283988 0.5935162  0.02163358
## [68]  {22750}               => {22749}  0.01283988 0.6296296  0.02039275
## [69]  {22730}               => {22728}  0.01262408 0.5000000  0.02524817
## [70]  {22730}               => {22726}  0.01483599 0.5876068  0.02524817
## [71]  {22730}               => {22727}  0.01694001 0.6709402  0.02524817
## [72]  {22142}               => {22144}  0.01095166 0.6323988  0.01731765
## [73]  {84596F}              => {84596B} 0.01213854 0.7812500  0.01553733
## [74]  {84596B}              => {84596F} 0.01213854 0.6232687  0.01947562
## [75]  {22141}               => {22144}  0.01068192 0.5689655  0.01877428
## [76]  {22617}               => {22138}  0.01677816 0.7334906  0.02287441
## [77]  {23200}               => {23199}  0.01683211 0.6638298  0.02535606
## [78]  {23200}               => {23202}  0.01294778 0.5106383  0.02535606
## [79]  {23200}               => {23203}  0.01462020 0.5765957  0.02535606
## [80]  {21231}               => {21232}  0.01327147 0.6456693  0.02055460
## [81]  {82483}               => {82486}  0.01478205 0.5383104  0.02746008
## [82]  {22328}               => {22326}  0.01413466 0.5720524  0.02470868
## [83]  {22385}               => {85099B} 0.01440440 0.5585774  0.02578766
## [84]  {21930}               => {85099B} 0.01337937 0.5265393  0.02541001
## [85]  {22866}               => {22867}  0.01294778 0.5095541  0.02541001
## [86]  {22867}               => {22866}  0.01294778 0.5063291  0.02557186
## [87]  {22866}               => {22865}  0.01515969 0.5966030  0.02541001
## [88]  {20712}               => {85099B} 0.01413466 0.5325203  0.02654294
## [89]  {22698}               => {22697}  0.02481657 0.8273381  0.02999568
## [90]  {22697}               => {22698}  0.02481657 0.6657019  0.03727881
## [91]  {22698}               => {22699}  0.02352180 0.7841727  0.02999568
## [92]  {22699}               => {22698}  0.02352180 0.5568327  0.04224212
## [93]  {22698}               => {22423}  0.01667026 0.5557554  0.02999568
## [94]  {22114}               => {22112}  0.01402676 0.5058366  0.02772982
## [95]  {21928}               => {21929}  0.01521364 0.5202952  0.02924040
## [96]  {21928}               => {85099B} 0.01726370 0.5904059  0.02924040
## [97]  {22835}               => {22112}  0.01553733 0.5702970  0.02724428
## [98]  {22804}               => {85123A} 0.01629262 0.7383863  0.02206517
## [99]  {22578}               => {22577}  0.01720975 0.7367206  0.02335995
## [100] {22577}               => {22578}  0.01720975 0.6889849  0.02497842
## [101] {23322}               => {23321}  0.01515969 0.5499022  0.02756798
## [102] {22867}               => {22865}  0.01440440 0.5632911  0.02557186
## [103] {85099C}              => {85099B} 0.01952956 0.5577812  0.03501295
## [104] {20719}               => {20724}  0.01559128 0.5442561  0.02864696
## [105] {20971}               => {20972}  0.01267803 0.5142232  0.02465473
## [106] {22951}               => {21212}  0.01019637 0.5338983  0.01909797
## [107] {22417}               => {21212}  0.01143720 0.5208845  0.02195727
## [108] {21791}               => {21790}  0.01348727 0.5154639  0.02616530
## [109] {21914}               => {21915}  0.01467415 0.5261122  0.02789167
## [110] {85099F}              => {85099B} 0.02233492 0.6330275  0.03528269
## [111] {22356}               => {20724}  0.01737160 0.6611910  0.02627320
## [112] {20723}               => {20724}  0.01596893 0.6016260  0.02654294
## [113] {23208}               => {23206}  0.01640052 0.5092127  0.03220760
## [114] {23208}               => {23209}  0.01720975 0.5343384  0.03220760
## [115] {21929}               => {85099B} 0.01785714 0.5498339  0.03247734
## [116] {22355}               => {20724}  0.01607682 0.5094017  0.03156021
## [117] {22728}               => {22726}  0.01850453 0.5595432  0.03307078
## [118] {22728}               => {22727}  0.02136383 0.6460033  0.03307078
## [119] {22697}               => {22699}  0.02918645 0.7829233  0.03727881
## [120] {22699}               => {22697}  0.02918645 0.6909323  0.04224212
## [121] {22697}               => {22423}  0.02017695 0.5412446  0.03727881
## [122] {22662}               => {22382}  0.01920587 0.5953177  0.03226155
## [123] {22662}               => {22383}  0.01618472 0.5016722  0.03226155
## [124] {22662}               => {20725}  0.01667026 0.5167224  0.03226155
## [125] {82494L}              => {82482}  0.02524817 0.5770654  0.04375270
## [126] {82482}               => {82494L} 0.02524817 0.5342466  0.04725939
## [127] {22699}               => {22423}  0.02265861 0.5363985  0.04224212
## [128] {23202}               => {23203}  0.02309020 0.5544041  0.04164868
## [129] {22386}               => {85099B} 0.02945619 0.6268657  0.04698964
## [130] {22551}               => {22554}  0.01575313 0.5043178  0.03123651
## [131] {21931}               => {85099B} 0.02341390 0.5607235  0.04175658
## [132] {22910}               => {22086}  0.02433103 0.6470588  0.03760250
## [133] {21975}               => {21212}  0.01440440 0.5047259  0.02853906
## [134] {22630}               => {22629}  0.02287441 0.6883117  0.03323263
## [135] {22629}               => {22630}  0.02287441 0.6022727  0.03798015
## [136] {22470}               => {22469}  0.02195727 0.5081149  0.04321321
## [137] {21733}               => {85123A} 0.02465473 0.6730486  0.03663142
## [138] {22726}               => {22727}  0.02859301 0.6717364  0.04256582
## [139] {22727}               => {22726}  0.02859301 0.6043330  0.04731334
## [140] {22411}               => {85099B} 0.02136383 0.5012658  0.04261977
## [141] {21977}               => {21212}  0.01807294 0.5007474  0.03609193
## [142] {23300}               => {23301}  0.02497842 0.7291339  0.03425766
## [143] {23301}               => {23300}  0.02497842 0.6124339  0.04078550
## [144] {84991}               => {21212}  0.01780319 0.5022831  0.03544454
## [145] {20726}               => {20725}  0.02335995 0.5280488  0.04423824
## [146] {22384}               => {20725}  0.02821536 0.5617615  0.05022659
## [147] {22745, 22746}        => {22748}  0.01003453 0.9073171  0.01105956
## [148] {22746, 22748}        => {22745}  0.01003453 0.8651163  0.01159905
## [149] {22745, 22748}        => {22746}  0.01003453 0.7322835  0.01370306
## [150] {22726, 22730}        => {22727}  0.01159905 0.7818182  0.01483599
## [151] {22727, 22730}        => {22726}  0.01159905 0.6847134  0.01694001
## [152] {23199, 23200}        => {23203}  0.01046612 0.6217949  0.01683211
## [153] {23200, 23203}        => {23199}  0.01046612 0.7158672  0.01462020
## [154] {23199, 23203}        => {23200}  0.01046612 0.6024845  0.01737160
## [155] {22697, 22698}        => {22699}  0.02104014 0.8478261  0.02481657
## [156] {22698, 22699}        => {22697}  0.02104014 0.8944954  0.02352180
## [157] {22697, 22699}        => {22698}  0.02104014 0.7208872  0.02918645
## [158] {22697, 22698}        => {22423}  0.01462020 0.5891304  0.02481657
## [159] {22423, 22698}        => {22697}  0.01462020 0.8770227  0.01667026
## [160] {22423, 22697}        => {22698}  0.01462020 0.7245989  0.02017695
## [161] {22698, 22699}        => {22423}  0.01429650 0.6077982  0.02352180
## [162] {22423, 22698}        => {22699}  0.01429650 0.8576052  0.01667026
## [163] {22423, 22699}        => {22698}  0.01429650 0.6309524  0.02265861
## [164] {22386, 85099F}       => {85099B} 0.01251618 0.7918089  0.01580708
## [165] {85099B, 85099F}      => {22386}  0.01251618 0.5603865  0.02233492
## [166] {22726, 22728}        => {22727}  0.01440440 0.7784257  0.01850453
## [167] {22727, 22728}        => {22726}  0.01440440 0.6742424  0.02136383
## [168] {22726, 22727}        => {22728}  0.01440440 0.5037736  0.02859301
## [169] {22697, 22699}        => {22423}  0.01683211 0.5767098  0.02918645
## [170] {22423, 22697}        => {22699}  0.01683211 0.8342246  0.02017695
## [171] {22423, 22699}        => {22697}  0.01683211 0.7428571  0.02265861
## [172] {23199, 23202}        => {23203}  0.01008848 0.6584507  0.01532154
## [173] {23199, 23203}        => {23202}  0.01008848 0.5807453  0.01737160
## [174] {20726, 22662}        => {22382}  0.01008848 0.7391304  0.01364912
## [175] {22382, 22662}        => {20726}  0.01008848 0.5252809  0.01920587
## [176] {22382, 22662}        => {22383}  0.01105956 0.5758427  0.01920587
## [177] {22383, 22662}        => {22382}  0.01105956 0.6833333  0.01618472
## [178] {22382, 22662}        => {20725}  0.01154510 0.6011236  0.01920587
## [179] {20725, 22662}        => {22382}  0.01154510 0.6925566  0.01667026
## [180] {22383, 22662}        => {20725}  0.01095166 0.6766667  0.01618472
## [181] {20725, 22662}        => {22383}  0.01095166 0.6569579  0.01667026
## [182] {23202, 23209}        => {23203}  0.01111351 0.8306452  0.01337937
## [183] {23202, 23203}        => {85099B} 0.01219249 0.5280374  0.02309020
## [184] {23202, 85099B}       => {23203}  0.01219249 0.6550725  0.01861243
## [185] {21931, 22386}        => {85099B} 0.01186880 0.7829181  0.01515969
## [186] {21931, 85099B}       => {22386}  0.01186880 0.5069124  0.02341390
## [187] {22386, 22411}        => {85099B} 0.01014243 0.7704918  0.01316357
## [188] {22386, 23203}        => {85099B} 0.01035822 0.7245283  0.01429650
## [189] {21931, 22411}        => {85099B} 0.01008848 0.7391304  0.01364912
## [190] {20726, 23206}        => {20725}  0.01046612 0.6510067  0.01607682
## [191] {22384, 23206}        => {20725}  0.01046612 0.6689655  0.01564523
## [192] {23206, 23209}        => {22383}  0.01078981 0.5263158  0.02050065
## [193] {22383, 23206}        => {23209}  0.01078981 0.5555556  0.01942167
## [194] {22383, 23209}        => {23206}  0.01078981 0.6042296  0.01785714
## [195] {23206, 23209}        => {20725}  0.01213854 0.5921053  0.02050065
## [196] {20725, 23206}        => {23209}  0.01213854 0.5784062  0.02098619
## [197] {20725, 23209}        => {23206}  0.01213854 0.5369928  0.02260466
## [198] {20727, 23206}        => {22383}  0.01089771 0.6312500  0.01726370
## [199] {22383, 23206}        => {20727}  0.01089771 0.5611111  0.01942167
## [200] {20727, 23206}        => {20725}  0.01100561 0.6375000  0.01726370
## [201] {20725, 23206}        => {20727}  0.01100561 0.5244216  0.02098619
## [202] {22382, 23206}        => {20725}  0.01057402 0.6322581  0.01672421
## [203] {20725, 23206}        => {22382}  0.01057402 0.5038560  0.02098619
## [204] {22383, 23206}        => {20725}  0.01176090 0.6055556  0.01942167
## [205] {20725, 23206}        => {22383}  0.01176090 0.5604113  0.02098619
## [206] {20726, 22384}        => {20728}  0.01057402 0.6163522  0.01715580
## [207] {20726, 20728}        => {22384}  0.01057402 0.5414365  0.01952956
## [208] {20726, 22384}        => {20727}  0.01068192 0.6226415  0.01715580
## [209] {20726, 20727}        => {22384}  0.01068192 0.5706052  0.01872033
## [210] {20726, 22384}        => {22382}  0.01078981 0.6289308  0.01715580
## [211] {22382, 22384}        => {20726}  0.01078981 0.5449591  0.01979931
## [212] {20726, 22384}        => {22383}  0.01057402 0.6163522  0.01715580
## [213] {20726, 22383}        => {22384}  0.01057402 0.5414365  0.01952956
## [214] {20726, 22384}        => {20725}  0.01278593 0.7452830  0.01715580
## [215] {20725, 20726}        => {22384}  0.01278593 0.5473441  0.02335995
## [216] {20726, 20728}        => {20727}  0.01057402 0.5414365  0.01952956
## [217] {20726, 20727}        => {20728}  0.01057402 0.5648415  0.01872033
## [218] {20726, 20728}        => {22382}  0.01138325 0.5828729  0.01952956
## [219] {20726, 22382}        => {20728}  0.01138325 0.5209877  0.02184937
## [220] {20728, 22382}        => {20726}  0.01138325 0.5396419  0.02109409
## [221] {20726, 20728}        => {22383}  0.01143720 0.5856354  0.01952956
## [222] {20726, 22383}        => {20728}  0.01143720 0.5856354  0.01952956
## [223] {20726, 20728}        => {20725}  0.01240829 0.6353591  0.01952956
## [224] {20725, 20726}        => {20728}  0.01240829 0.5311778  0.02335995
## [225] {20725, 20728}        => {20726}  0.01240829 0.5010893  0.02476262
## [226] {20726, 20727}        => {22382}  0.01132931 0.6051873  0.01872033
## [227] {20726, 22382}        => {20727}  0.01132931 0.5185185  0.02184937
## [228] {20727, 22382}        => {20726}  0.01132931 0.5023923  0.02255071
## [229] {20726, 20727}        => {22383}  0.01127536 0.6023055  0.01872033
## [230] {20726, 22383}        => {20727}  0.01127536 0.5773481  0.01952956
## [231] {20726, 20727}        => {20725}  0.01240829 0.6628242  0.01872033
## [232] {20725, 20726}        => {20727}  0.01240829 0.5311778  0.02335995
## [233] {20726, 22382}        => {22383}  0.01176090 0.5382716  0.02184937
## [234] {20726, 22383}        => {22382}  0.01176090 0.6022099  0.01952956
## [235] {20726, 22382}        => {20725}  0.01391886 0.6370370  0.02184937
## [236] {20725, 20726}        => {22382}  0.01391886 0.5958430  0.02335995
## [237] {20725, 22382}        => {20726}  0.01391886 0.5524625  0.02519422
## [238] {20726, 22383}        => {20725}  0.01375701 0.7044199  0.01952956
## [239] {20725, 20726}        => {22383}  0.01375701 0.5889145  0.02335995
## [240] {23209, 85099B}       => {23203}  0.01089771 0.7921569  0.01375701
## [241] {20725, 23203}        => {23209}  0.01073587 0.7713178  0.01391886
## [242] {22384, 23209}        => {20725}  0.01154510 0.6903226  0.01672421
## [243] {20725, 23209}        => {22384}  0.01154510 0.5107399  0.02260466
## [244] {20728, 22384}        => {20727}  0.01402676 0.6088993  0.02303625
## [245] {20727, 22384}        => {20728}  0.01402676 0.5603448  0.02503237
## [246] {20727, 20728}        => {22384}  0.01402676 0.6175772  0.02271256
## [247] {20728, 22384}        => {22382}  0.01197669 0.5199063  0.02303625
## [248] {22382, 22384}        => {20728}  0.01197669 0.6049046  0.01979931
## [249] {20728, 22382}        => {22384}  0.01197669 0.5677749  0.02109409
## [250] {20728, 22384}        => {22383}  0.01251618 0.5433255  0.02303625
## [251] {22383, 22384}        => {20728}  0.01251618 0.5800000  0.02157963
## [252] {20728, 22383}        => {22384}  0.01251618 0.5132743  0.02438498
## [253] {20728, 22384}        => {20725}  0.01505179 0.6533958  0.02303625
## [254] {20725, 22384}        => {20728}  0.01505179 0.5334608  0.02821536
## [255] {20725, 20728}        => {22384}  0.01505179 0.6078431  0.02476262
## [256] {22382, 22384}        => {20727}  0.01213854 0.6130790  0.01979931
## [257] {20727, 22382}        => {22384}  0.01213854 0.5382775  0.02255071
## [258] {20727, 22384}        => {22383}  0.01310962 0.5237069  0.02503237
## [259] {22383, 22384}        => {20727}  0.01310962 0.6075000  0.02157963
## [260] {20727, 22383}        => {22384}  0.01310962 0.5225806  0.02508632
## [261] {20727, 22384}        => {20725}  0.01661631 0.6637931  0.02503237
## [262] {20725, 22384}        => {20727}  0.01661631 0.5889101  0.02821536
## [263] {20725, 20727}        => {22384}  0.01661631 0.5957447  0.02789167
## [264] {22382, 22384}        => {22383}  0.01068192 0.5395095  0.01979931
## [265] {22382, 22384}        => {20725}  0.01354122 0.6839237  0.01979931
## [266] {20725, 22382}        => {22384}  0.01354122 0.5374732  0.02519422
## [267] {22383, 22384}        => {20725}  0.01510574 0.7000000  0.02157963
## [268] {20725, 22384}        => {22383}  0.01510574 0.5353728  0.02821536
## [269] {20725, 22383}        => {22384}  0.01510574 0.5394990  0.02799957
## [270] {22384, 85099B}       => {20725}  0.01008848 0.6750903  0.01494389
## [271] {20727, 23209}        => {22383}  0.01003453 0.5568862  0.01801899
## [272] {22383, 23209}        => {20727}  0.01003453 0.5619335  0.01785714
## [273] {20727, 23209}        => {20725}  0.01116746 0.6197605  0.01801899
## [274] {22382, 23209}        => {20725}  0.01003453 0.6019417  0.01667026
## [275] {22383, 23209}        => {20725}  0.01143720 0.6404834  0.01785714
## [276] {20725, 23209}        => {22383}  0.01143720 0.5059666  0.02260466
## [277] {20727, 20728}        => {22382}  0.01203064 0.5296912  0.02271256
## [278] {20728, 22382}        => {20727}  0.01203064 0.5703325  0.02109409
## [279] {20727, 22382}        => {20728}  0.01203064 0.5334928  0.02255071
## [280] {20727, 20728}        => {22383}  0.01359517 0.5985748  0.02271256
## [281] {20728, 22383}        => {20727}  0.01359517 0.5575221  0.02438498
## [282] {20727, 22383}        => {20728}  0.01359517 0.5419355  0.02508632
## [283] {20727, 20728}        => {20725}  0.01413466 0.6223278  0.02271256
## [284] {20725, 20728}        => {20727}  0.01413466 0.5708061  0.02476262
## [285] {20725, 20727}        => {20728}  0.01413466 0.5067698  0.02789167
## [286] {20728, 22382}        => {22383}  0.01289383 0.6112532  0.02109409
## [287] {20728, 22383}        => {22382}  0.01289383 0.5287611  0.02438498
## [288] {22382, 22383}        => {20728}  0.01289383 0.5346756  0.02411524
## [289] {20728, 22382}        => {20725}  0.01267803 0.6010230  0.02109409
## [290] {20725, 20728}        => {22382}  0.01267803 0.5119826  0.02476262
## [291] {20725, 22382}        => {20728}  0.01267803 0.5032120  0.02519422
## [292] {20728, 22383}        => {20725}  0.01488994 0.6106195  0.02438498
## [293] {20725, 20728}        => {22383}  0.01488994 0.6013072  0.02476262
## [294] {20725, 22383}        => {20728}  0.01488994 0.5317919  0.02799957
## [295] {20727, 22382}        => {22383}  0.01359517 0.6028708  0.02255071
## [296] {20727, 22383}        => {22382}  0.01359517 0.5419355  0.02508632
## [297] {22382, 22383}        => {20727}  0.01359517 0.5637584  0.02411524
## [298] {20727, 22382}        => {20725}  0.01386491 0.6148325  0.02255071
## [299] {20725, 22382}        => {20727}  0.01386491 0.5503212  0.02519422
## [300] {20727, 22383}        => {20725}  0.01510574 0.6021505  0.02508632
## [301] {20725, 20727}        => {22383}  0.01510574 0.5415861  0.02789167
## [302] {20725, 22383}        => {20727}  0.01510574 0.5394990  0.02799957
## [303] {22382, 22383}        => {20725}  0.01462020 0.6062640  0.02411524
## [304] {20725, 22382}        => {22383}  0.01462020 0.5802998  0.02519422
## [305] {20725, 22383}        => {22382}  0.01462020 0.5221580  0.02799957
## [306] {22697, 22698, 22699} => {22423}  0.01289383 0.6128205  0.02104014
## [307] {22423, 22697, 22698} => {22699}  0.01289383 0.8819188  0.01462020
## [308] {22423, 22698, 22699} => {22697}  0.01289383 0.9018868  0.01429650
## [309] {22423, 22697, 22699} => {22698}  0.01289383 0.7660256  0.01683211
## [310] {20727, 20728, 22384} => {20725}  0.01041217 0.7423077  0.01402676
## [311] {20725, 20728, 22384} => {20727}  0.01041217 0.6917563  0.01505179
## [312] {20725, 20727, 22384} => {20728}  0.01041217 0.6266234  0.01661631
## [313] {20725, 20727, 20728} => {22384}  0.01041217 0.7366412  0.01413466
##       lift      count
## [1]   61.909259 202  
## [2]   61.909259 202  
## [3]   49.700457 197  
## [4]   49.700457 197  
## [5]   52.381694 206  
## [6]   52.381694 206  
## [7]   36.961117 192  
## [8]   36.961117 192  
## [9]   38.294291 196  
## [10]  38.294291 196  
## [11]  39.112875 201  
## [12]  39.112875 201  
## [13]  18.292105 186  
## [14]  47.228027 236  
## [15]  47.228027 236  
## [16]  17.059304 192  
## [17]  32.361921 228  
## [18]  32.361921 228  
## [19]  44.358383 214  
## [20]  44.358383 214  
## [21]  24.783569 188  
## [22]  34.244111 193  
## [23]  34.244111 193  
## [24]  27.670783 202  
## [25]  27.438790 200  
## [26]  47.930714 229  
## [27]  47.930714 229  
## [28]  30.752788 190  
## [29]  30.752788 190  
## [30]  26.866485 215  
## [31]  36.942556 254  
## [32]  36.942556 254  
## [33]  12.705876 190  
## [34]   5.961354 194  
## [35]  15.321541 210  
## [36]  14.834366 226  
## [37]  25.747424 192  
## [38]  22.791658 200  
## [39]  13.713049 190  
## [40]   9.765868 255  
## [41]  47.718003 205  
## [42]  47.718003 205  
## [43]  45.706487 215  
## [44]  45.706487 215  
## [45]  33.461633 211  
## [46]  33.461633 211  
## [47]  14.396842 220  
## [48]  14.482952 246  
## [49]  16.970061 188  
## [50]  27.315159 246  
## [51]  27.315159 246  
## [52]  35.053185 226  
## [53]  35.053185 226  
## [54]  29.010549 200  
## [55]  13.820994 189  
## [56]  17.842556 229  
## [57]  40.859399 199  
## [58]  40.859399 199  
## [59]  36.057268 225  
## [60]  36.057268 225  
## [61]   8.990512 214  
## [62]  43.061242 254  
## [63]  43.061242 254  
## [64]  17.645089 265  
## [65]  20.129072 245  
## [66]  17.731363 203  
## [67]  29.104276 238  
## [68]  29.104276 238  
## [69]  15.119086 234  
## [70]  13.804665 275  
## [71]  14.180783 314  
## [72]  27.843571 203  
## [73]  40.114266 225  
## [74]  40.114266 225  
## [75]  25.050700 198  
## [76]  15.920353 311  
## [77]  17.137533 312  
## [78]  12.260611 240  
## [79]   9.896091 271  
## [80]  20.563790 246  
## [81]  17.849950 274  
## [82]  17.821115 262  
## [83]   6.471119 267  
## [84]   6.099958 248  
## [85]  19.926362 240  
## [86]  19.926362 240  
## [87]  19.333274 281  
## [88]   6.169248 262  
## [89]  22.193256 460  
## [90]  22.193256 460  
## [91]  18.563760 436  
## [92]  18.563760 436  
## [93]   6.045471 309  
## [94]  13.394553 260  
## [95]  16.020252 282  
## [96]   6.839852 320  
## [97]  15.101465 288  
## [98]   6.919479 302  
## [99]  29.494281 319  
## [100] 29.494281 319  
## [101] 17.513722 281  
## [102] 18.253784 267  
## [103]  6.461895 362  
## [104] 13.651328 289  
## [105] 17.816152 235  
## [106]  9.617433 189  
## [107]  9.383008 212  
## [108] 13.233572 250  
## [109] 17.383272 272  
## [110]  7.333624 414  
## [111] 16.584351 322  
## [112] 15.090311 296  
## [113] 10.899269 304  
## [114]  9.845423 319  
## [115]  6.369826 331  
## [116] 12.777091 298  
## [117] 13.145365 343  
## [118] 13.653725 396  
## [119] 18.534184 541  
## [120] 18.534184 541  
## [121]  5.887623 374  
## [122] 11.168835 356  
## [123]  8.915625 300  
## [124]  7.430540 309  
## [125] 12.210597 468  
## [126] 12.210597 468  
## [127]  5.834907 420  
## [128]  9.515218 428  
## [129]  7.262239 546  
## [130] 15.925101 292  
## [131]  6.495982 434  
## [132] 12.238655 451  
## [133]  9.091933 267  
## [134] 18.122934 424  
## [135] 18.122934 424  
## [136]  9.800642 407  
## [137]  6.307194 457  
## [138] 14.197612 530  
## [139] 14.197612 530  
## [140]  5.807165 396  
## [141]  9.020266 335  
## [142] 17.877282 463  
## [143] 17.877282 463  
## [144]  9.047930 330  
## [145]  7.593415 433  
## [146]  8.078209 523  
## [147] 48.607021 186  
## [148] 50.746188 186  
## [149] 53.863517 186  
## [150] 16.524267 215  
## [151] 16.085991 215  
## [152] 10.671842 194  
## [153] 18.480938 194  
## [154] 23.760962 194  
## [155] 20.070631 390  
## [156] 23.994742 390  
## [157] 24.033032 390  
## [158]  6.408522 271  
## [159] 23.526037 271  
## [160] 24.156773 271  
## [161]  6.611588 265  
## [162] 20.302132 265  
## [163] 21.034772 265  
## [164]  9.173106 232  
## [165] 11.925745 232  
## [166] 16.452563 267  
## [167] 15.839997 267  
## [168] 15.233193 267  
## [169]  6.273411 312  
## [170] 19.748643 312  
## [171] 19.927062 312  
## [172] 11.300965 187  
## [173] 13.943906 187  
## [174] 13.866925 187  
## [175] 11.873911 187  
## [176] 10.233768 205  
## [177] 12.820108 205  
## [178]  8.644241 214  
## [179] 12.993148 214  
## [180]  9.730561 203  
## [181] 11.675333 203  
## [182] 14.256332 206  
## [183]  6.117313 226  
## [184] 11.242984 226  
## [185]  9.070107 220  
## [186] 10.787749 220  
## [187]  8.926148 188  
## [188]  8.393660 192  
## [189]  8.562826 187  
## [190]  9.361567 194  
## [191]  9.619818 194  
## [192]  9.353585 200  
## [193] 10.236360 200  
## [194] 12.933025 200  
## [195]  8.514556 225  
## [196] 10.657392 225  
## [197] 11.493879 225  
## [198] 11.218456 202  
## [199]  9.886650 202  
## [200]  9.167339 204  
## [201]  9.240189 204  
## [202]  9.091959 196  
## [203]  9.452911 196  
## [204]  8.707973 218  
## [205]  9.959525 218  
## [206] 11.826816 196  
## [207] 10.779878 196  
## [208] 10.970801 198  
## [209] 11.360621 198  
## [210] 11.799455 200  
## [211] 12.318735 200  
## [212] 10.953695 196  
## [213] 10.779878 196  
## [214] 10.717274 237  
## [215] 10.897498 237  
## [216]  9.539987 196  
## [217] 10.838408 196  
## [218] 10.935357 211  
## [219]  9.996923 211  
## [220] 12.198540 211  
## [221] 10.407802 212  
## [222] 11.237409 212  
## [223]  9.136553 230  
## [224] 10.192456 230  
## [225] 11.327063 230  
## [226] 11.354000 210  
## [227]  9.136178 210  
## [228] 11.356518 210  
## [229] 10.704060 209  
## [230] 10.172741 209  
## [231]  9.531505 230  
## [232]  9.359232 230  
## [233]  9.566062 218  
## [234] 11.298141 218  
## [235]  9.160682 258  
## [236] 11.178689 258  
## [237] 12.488348 258  
## [238] 10.129656 255  
## [239] 10.466079 255  
## [240] 13.595759 202  
## [241] 14.211876 199  
## [242]  9.926935 214  
## [243] 10.168715 214  
## [244] 10.728667 260  
## [245] 10.752124 260  
## [246] 12.295823 260  
## [247]  9.754032 222  
## [248] 11.607156 222  
## [249] 11.304271 222  
## [250]  9.655879 232  
## [251] 11.129275 232  
## [252] 10.219176 232  
## [253]  9.395923 279  
## [254] 10.236262 279  
## [255] 12.102020 279  
## [256] 10.802312 225  
## [257] 10.716984 225  
## [258]  9.307221 243  
## [259] 10.704011 243  
## [260] 10.404463 243  
## [261]  9.545438 308  
## [262] 10.376462 308  
## [263] 11.861142 308  
## [264]  9.588062 198  
## [265]  9.834918 251  
## [266] 10.700971 251  
## [267] 10.066098 280  
## [268]  9.514546 280  
## [269] 10.741304 280  
## [270]  9.707892 187  
## [271]  9.896877 186  
## [272]  9.901141 186  
## [273]  8.912242 207  
## [274]  8.656006 186  
## [275]  9.210240 212  
## [276]  8.991943 212  
## [277]  9.937608 223  
## [278] 10.049128 223  
## [279] 10.236877 223  
## [280] 10.637759 252  
## [281]  9.823413 252  
## [282] 10.398878 252  
## [283]  8.949161 262  
## [284] 10.057473 262  
## [285]  9.724105 262  
## [286] 10.863077 239  
## [287]  9.920157 239  
## [288] 10.259573 239  
## [289]  8.642795 235  
## [290]  9.605373 235  
## [291]  9.655836 235  
## [292]  8.780793 276  
## [293] 10.686318 276  
## [294] 10.204239 276  
## [295] 10.714107 252  
## [296] 10.167324 252  
## [297]  9.933294 252  
## [298]  8.841378 257  
## [299]  9.696534 257  
## [300]  8.659009 280  
## [301]  9.624966 280  
## [302]  9.505850 280  
## [303]  8.718161 271  
## [304] 10.312979 271  
## [305]  9.796276 271  
## [306]  6.666221 239  
## [307] 20.877710 239  
## [308] 24.193015 239  
## [309] 25.537862 239  
## [310] 10.674488 193  
## [311] 12.188588 193  
## [312] 12.023904 193  
## [313] 14.666361 193

Frequency Distribution of Itemsets

library(arules)

# Convert to transaction format
transactions <- as(split(aggregated_data$items, aggregated_data$InvoiceNo), "transactions")

# Generate itemsets of various lengths
itemsets_1 <- eclat(transactions, parameter = list(support = 0.01, maxlen = 1))
## Eclat
## 
## parameter specification:
##  tidLists support minlen maxlen            target  ext
##     FALSE    0.01      1      1 frequent itemsets TRUE
## 
## algorithmic control:
##  sparse sort verbose
##       7   -2    TRUE
## 
## Absolute minimum support count: 185
## eclat - zero frequent items
itemsets_2 <- eclat(transactions, parameter = list(support = 0.01, maxlen = 2))
## Eclat
## 
## parameter specification:
##  tidLists support minlen maxlen            target  ext
##     FALSE    0.01      1      2 frequent itemsets TRUE
## 
## algorithmic control:
##  sparse sort verbose
##       7   -2    TRUE
## 
## Absolute minimum support count: 185
## eclat - zero frequent items
itemsets_3 <- eclat(transactions, parameter = list(support = 0.01, maxlen = 3))
## Eclat
## 
## parameter specification:
##  tidLists support minlen maxlen            target  ext
##     FALSE    0.01      1      3 frequent itemsets TRUE
## 
## algorithmic control:
##  sparse sort verbose
##       7   -2    TRUE
## 
## Absolute minimum support count: 185
## eclat - zero frequent items
# Summary of itemsets
summary(itemsets_1)
## set of 0 itemsets
summary(itemsets_2)
## set of 0 itemsets
summary(itemsets_3)
## set of 0 itemsets

Handle Data Quality Issues

# Check for missing values or inconsistencies
sum(is.na(transaction_data$StockCode))
## [1] 0
sum(transaction_data$Quantity < 0)  # If negative quantities exist
## [1] 0
# Remove or correct inconsistencies
transaction_data_clean <- transaction_data %>%
  filter(Quantity > 0) %>%
  drop_na()

b. Rule Generation

  1. Frequent Itemsets
# Generate frequent itemsets
frequent_itemsets <- apriori(transactions, parameter = list(support = 0.01, target = "frequent itemsets"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##          NA    0.1    1 none FALSE            TRUE       5    0.01      1
##  maxlen            target  ext
##      10 frequent itemsets TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 185 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[17636 item(s), 18536 transaction(s)] done [0.04s].
## sorting and recoding items ... [0 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 done [0.00s].
## sorting transactions ... done [0.00s].
## writing ... [0 set(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
# Inspect frequent itemsets
inspect(frequent_itemsets)
  1. Association Rules
# Generate rules
rules <- apriori(transactions, parameter = list(support = 0.01, confidence = 0.5, target = "rules"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5    0.01      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 185 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[17636 item(s), 18536 transaction(s)] done [0.03s].
## sorting and recoding items ... [0 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 done [0.00s].
## writing ... [0 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
# Top rules by various metrics
top_rules_support <- head(sort(rules, by = "support"), 10)
top_rules_confidence <- head(sort(rules, by = "confidence"), 10)
top_rules_lift <- head(sort(rules, by = "lift"), 10)

# Inspect top rules
inspect(top_rules_support)
inspect(top_rules_confidence)
inspect(top_rules_lift)
  1. Impact of Threshold Values
# Adjust thresholds
rules_10 <- apriori(transactions, parameter = list(support = 0.1, confidence = 0.5, target = "rules"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5     0.1      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 1853 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[17636 item(s), 18536 transaction(s)] done [0.03s].
## sorting and recoding items ... [0 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 done [0.00s].
## writing ... [0 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
rules_05 <- apriori(transactions, parameter = list(support = 0.05, confidence = 0.5, target = "rules"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5    0.05      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 926 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[17636 item(s), 18536 transaction(s)] done [0.02s].
## sorting and recoding items ... [0 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 done [0.00s].
## writing ... [0 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
# Summary of rules with adjusted thresholds
summary(rules_10)
## set of 0 rules
summary(rules_05)
## set of 0 rules

c. Rule Evaluation

  1. Calculate Support, Confidence, and Lift
# Extract rule metrics
rule_metrics <- data.frame(
  support = quality(rules)$support,
  confidence = quality(rules)$confidence,
  lift = quality(rules)$lift
)

# Find rules with the highest lift
highest_lift_rules <- rules[order(-quality(rules)$lift)]
inspect(head(highest_lift_rules, 10))
  1. Alignment with Business Objectives
# Review top rules and align with business goals
top_rules_business <- head(sort(rules, by = "lift"), 10)
inspect(top_rules_business)
  1. Identify Unexpected Rules
# Identify and interpret unexpected rules
unexpected_rules <- rules[quality(rules)$lift < 1]  # Example condition
inspect(unexpected_rules)

Matrix Plots

# Load necessary libraries
library(arules)
library(arulesViz)
library(dplyr)
library(tidyr)
library(ggplot2)



# Data cleaning and transformation
transaction_data <- data %>%
  filter(Quantity > 0) %>%
  select(InvoiceNo, StockCode)  # Select relevant columns

# Aggregate transaction data
aggregated_data <- transaction_data %>%
  group_by(InvoiceNo) %>%
  summarize(items = paste(StockCode, collapse = ",")) %>%
  ungroup()

# Convert to transactions format
split_items <- strsplit(aggregated_data$items, ",")
transactions <- as(split_items, "transactions")
## Warning in asMethod(object): removing duplicated items in transactions
# Generate association rules with adjusted parameters
rules <- apriori(transactions, parameter = list(support = 0.01, confidence = 0.5, maxlen = 5))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5    0.01      1
##  maxlen target  ext
##       5  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 185 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[3665 item(s), 18536 transaction(s)] done [0.34s].
## sorting and recoding items ... [625 item(s)] done [0.01s].
## creating transaction tree ... done [0.02s].
## checking subsets of size 1 2 3 4 done [0.04s].
## writing ... [313 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
# Check the number of rules
cat("Number of rules generated:", length(rules), "\n")
## Number of rules generated: 313
# Plot the rules if there are any
if (length(rules) > 0) {
  # Save the plot to a PNG file with increased size
  png("rules_plot.png", width = 1200, height = 1200, res = 150)
  plot(rules, method = "matrix", control = list(reorder = "measure"))
  dev.off()

  # Alternatively, plot interactively
  library(plotly)
  plotly::plot_ly(data = as(rules, "data.frame"), x = ~support, y = ~confidence, color = ~lift, type = 'scatter', mode = 'markers')
  
} else {
  message("No rules to plot.")
}
## Itemsets in Antecedent (LHS)
##   [1] "{23172}"             "{23171}"             "{22745,22748}"      
##   [4] "{22746,22748}"       "{22745,22746}"       "{22746}"            
##   [7] "{22745}"             "{23174}"             "{23175}"            
##  [10] "{22748}"             "{23254}"             "{23256}"            
##  [13] "{21933}"             "{21932}"             "{84596F}"           
##  [16] "{84596B}"            "{22569}"             "{23170}"            
##  [19] "{47590A}"            "{47590B}"            "{82580}"            
##  [22] "{82581}"             "{21668}"             "{21669}"            
##  [25] "{22570}"             "{21094}"             "{84997C}"           
##  [28] "{84997D}"            "{22578}"             "{21086}"            
##  [31] "{22579}"             "{23294}"             "{23295}"            
##  [34] "{22577}"             "{22750}"             "{22749}"            
##  [37] "{23296}"             "{22142}"             "{23293}"            
##  [40] "{84997B}"            "{22423,22697,22699}" "{22141}"            
##  [43] "{22192}"             "{22423,22698,22699}" "{23173}"            
##  [46] "{22191}"             "{22423,22697}"       "{22423,22698}"      
##  [49] "{22423,22697,22698}" "{21231}"             "{22423,22699}"      
##  [52] "{23343}"             "{22866}"             "{22867}"            
##  [55] "{23199,23203}"       "{23200,23203}"       "{22627}"            
##  [58] "{22629}"             "{22630}"             "{23300}"            
##  [61] "{23301}"             "{82483}"             "{22328}"            
##  [64] "{20971}"             "{23439}"             "{22625}"            
##  [67] "{23322}"             "{21914}"             "{22632}"            
##  [70] "{22356}"             "{22726,22730}"       "{22726,22728}"      
##  [73] "{22727,22730}"       "{22551}"             "{22617}"            
##  [76] "{22727,22728}"       "{22698}"             "{22697}"            
##  [79] "{22698,22699}"       "{22726,22727}"       "{22697,22699}"      
##  [82] "{22835}"             "{20723}"             "{22725}"            
##  [85] "{20725,20727,20728}" "{22729}"             "{22730}"            
##  [88] "{22699}"             "{23202,23209}"       "{20725,23203}"      
##  [91] "{22726}"             "{22727}"             "{20726,22662}"      
##  [94] "{22661}"             "{20719}"             "{23209,85099B}"     
##  [97] "{22728}"             "{22114}"             "{22697,22698}"      
## [100] "{21791}"             "{23200}"             "{22355}"            
## [103] "{20725,22662}"       "{22910}"             "{82482}"            
## [106] "{82494L}"            "{20725,20728,22384}" "{20725,20727,22384}"
## [109] "{85099B,85099F}"     "{21928}"             "{23199,23202}"      
## [112] "{22383,22662}"       "{20726,22384}"       "{23202,85099B}"     
## [115] "{22382,22384}"       "{21931,85099B}"      "{20726,20727}"      
## [118] "{20725,20728}"       "{20726,22383}"       "{22383,23209}"      
## [121] "{20727,20728,22384}" "{23199,23200}"       "{22383,22384}"      
## [124] "{20728,22382}"       "{20725,22382}"       "{20727,20728}"      
## [127] "{20725,20726}"       "{20725,20727}"       "{20727,22382}"      
## [130] "{23208}"             "{22382,22662}"       "{20725,23209}"      
## [133] "{20727,23206}"       "{20726,20728}"       "{20725,22383}"      
## [136] "{20725,22384}"       "{22384,23209}"       "{20727,22383}"      
## [139] "{20728,22384}"       "{20727,22384}"       "{20725,23206}"      
## [142] "{22470}"             "{21136}"             "{22384,85099B}"     
## [145] "{20728,22383}"       "{22382,22383}"       "{22384,23206}"      
## [148] "{22951}"             "{22383,23206}"       "{23202}"            
## [151] "{20726,22382}"       "{20727,23209}"       "{22417}"            
## [154] "{20726,23206}"       "{22386,85099F}"      "{22662}"            
## [157] "{22382,23206}"       "{21975}"             "{21931,22386}"      
## [160] "{84991}"             "{21977}"             "{23243}"            
## [163] "{23206,23209}"       "{22386,22411}"       "{22382,23209}"      
## [166] "{21931,22411}"       "{22386,23203}"       "{22384}"            
## [169] "{20726}"             "{85099F}"            "{22386}"            
## [172] "{22804}"             "{22697,22698,22699}" "{21931}"            
## [175] "{22385}"             "{85099C}"            "{21929}"            
## [178] "{21733}"             "{20712}"             "{23202,23203}"      
## [181] "{21930}"             "{22411}"            
## Itemsets in Consequent (RHS)
##  [1] "{22423}"  "{85123A}" "{85099B}" "{22720}"  "{20725}"  "{21212}" 
##  [7] "{84879}"  "{22469}"  "{20727}"  "{22383}"  "{20728}"  "{22382}" 
## [13] "{23209}"  "{22384}"  "{22386}"  "{23203}"  "{23206}"  "{20726}" 
## [19] "{82482}"  "{82494L}" "{22086}"  "{23202}"  "{21790}"  "{22112}" 
## [25] "{20724}"  "{22726}"  "{22727}"  "{22728}"  "{22138}"  "{22554}" 
## [31] "{21929}"  "{21915}"  "{21080}"  "{23321}"  "{23199}"  "{20972}" 
## [37] "{22326}"  "{82486}"  "{23300}"  "{23301}"  "{22624}"  "{22699}" 
## [43] "{22865}"  "{22629}"  "{22630}"  "{22867}"  "{22866}"  "{23344}" 
## [49] "{21232}"  "{22697}"  "{22698}"  "{23200}"  "{22193}"  "{22144}" 
## [55] "{23293}"  "{22568}"  "{84997D}" "{22750}"  "{22749}"  "{22577}" 
## [61] "{23296}"  "{23295}"  "{22578}"  "{84997C}" "{21668}"  "{21669}" 
## [67] "{23294}"  "{22579}"  "{82580}"  "{82581}"  "{47590A}" "{47590B}"
## [73] "{23173}"  "{22569}"  "{22570}"  "{84596F}" "{84596B}" "{21933}" 
## [79] "{21932}"  "{23254}"  "{23256}"  "{23175}"  "{23174}"  "{22748}" 
## [85] "{22745}"  "{21086}"  "{21094}"  "{23170}"  "{22746}"  "{23171}" 
## [91] "{23172}"
# Additional code to inspect and analyze rules
if (length(rules) > 0) {
  # Inspect the top rules by support
  top_rules_support <- head(sort(rules, by = "support"), 10)
  cat("Top rules by support:\n")
  inspect(top_rules_support)
  
  # Inspect the top rules by confidence
  top_rules_confidence <- head(sort(rules, by = "confidence"), 10)
  cat("Top rules by confidence:\n")
  inspect(top_rules_confidence)
  
  # Inspect the top rules by lift
  top_rules_lift <- head(sort(rules, by = "lift"), 10)
  cat("Top rules by lift:\n")
  inspect(top_rules_lift)
}
## Top rules by support:
##      lhs         rhs      support    confidence coverage   lift      count
## [1]  {22386}  => {85099B} 0.02945619 0.6268657  0.04698964  7.262239 546  
## [2]  {22697}  => {22699}  0.02918645 0.7829233  0.03727881 18.534184 541  
## [3]  {22699}  => {22697}  0.02918645 0.6909323  0.04224212 18.534184 541  
## [4]  {22726}  => {22727}  0.02859301 0.6717364  0.04256582 14.197612 530  
## [5]  {22727}  => {22726}  0.02859301 0.6043330  0.04731334 14.197612 530  
## [6]  {22384}  => {20725}  0.02821536 0.5617615  0.05022659  8.078209 523  
## [7]  {82494L} => {82482}  0.02524817 0.5770654  0.04375270 12.210597 468  
## [8]  {82482}  => {82494L} 0.02524817 0.5342466  0.04725939 12.210597 468  
## [9]  {23300}  => {23301}  0.02497842 0.7291339  0.03425766 17.877282 463  
## [10] {23301}  => {23300}  0.02497842 0.6124339  0.04078550 17.877282 463  
## Top rules by confidence:
##      lhs                      rhs     support    confidence coverage   lift    
## [1]  {22745, 22746}        => {22748} 0.01003453 0.9073171  0.01105956 48.60702
## [2]  {22423, 22698, 22699} => {22697} 0.01289383 0.9018868  0.01429650 24.19302
## [3]  {23172}               => {23171} 0.01089771 0.9017857  0.01208459 61.90926
## [4]  {22698, 22699}        => {22697} 0.02104014 0.8944954  0.02352180 23.99474
## [5]  {22423, 22697, 22698} => {22699} 0.01289383 0.8819188  0.01462020 20.87771
## [6]  {23172}               => {23170} 0.01062797 0.8794643  0.01208459 49.70046
## [7]  {22423, 22698}        => {22697} 0.01462020 0.8770227  0.01667026 23.52604
## [8]  {22746, 22748}        => {22745} 0.01003453 0.8651163  0.01159905 50.74619
## [9]  {22423, 22698}        => {22699} 0.01429650 0.8576052  0.01667026 20.30213
## [10] {22746}               => {22748} 0.01159905 0.8531746  0.01359517 45.70649
##      count
## [1]  186  
## [2]  239  
## [3]  202  
## [4]  390  
## [5]  239  
## [6]  197  
## [7]  271  
## [8]  186  
## [9]  265  
## [10] 215  
## Top rules by lift:
##      lhs               rhs     support    confidence coverage   lift     count
## [1]  {23172}        => {23171} 0.01089771 0.9017857  0.01208459 61.90926 202  
## [2]  {23171}        => {23172} 0.01089771 0.7481481  0.01456625 61.90926 202  
## [3]  {22745, 22748} => {22746} 0.01003453 0.7322835  0.01370306 53.86352 186  
## [4]  {23175}        => {23174} 0.01111351 0.7573529  0.01467415 52.38169 206  
## [5]  {23174}        => {23175} 0.01111351 0.7686567  0.01445835 52.38169 206  
## [6]  {22746, 22748} => {22745} 0.01003453 0.8651163  0.01159905 50.74619 186  
## [7]  {23172}        => {23170} 0.01062797 0.8794643  0.01208459 49.70046 197  
## [8]  {23170}        => {23172} 0.01062797 0.6006098  0.01769530 49.70046 197  
## [9]  {22745, 22746} => {22748} 0.01003453 0.9073171  0.01105956 48.60702 186  
## [10] {23171}        => {23170} 0.01235434 0.8481481  0.01456625 47.93071 229
# Optionally: Save rules to a CSV file
write(rules, file = "rules.csv", sep = ",")

d. Comparative Analysis

Product Performance Comparison

# Aggregate data for comparative analysis
product_performance <- sample_data %>%
  group_by(StockCode) %>%
  summarize(Revenue = sum(UnitPrice * Quantity), .groups = 'drop')

# Comparative bar chart
ggplot(product_performance, aes(x = reorder(StockCode, -Revenue), y = Revenue, fill = StockCode)) +
  geom_bar(stat = "identity") +
  theme_minimal() +
  labs(title = "Comparison of Product Performance",
       x = "Product",
       y = "Revenue") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))

Conclusion

This report summarizes advanced data visualizations for understanding market basket patterns and customer behavior. Each visualization technique provides insights into different aspects of the data, helping to uncover trends and relationships.

Additional Resources